from flask import Flask
from flask import request

# 创建Flask对象-Httpd WEB服务对象
app = Flask(__name__) # __name__可以是任意的小写字母

# 指定资源访问的路由
@app.route('/hi', methods=['GET','POST','PUT','DELETE'])
def get():
    #request是请求对象（HttpRequest），它包含请求路径、请求方法、请求头、上传表单数据、文件等信息。
    #获取平台参数：platform
    #只支持pc访问
    platform = request.args.get('platform','pc')
    if platform.lower() != 'pc':
        return '''
            <h2>目前只支持安卓</h2>
        '''

    if request.method == 'GET':
        return '''
        <form action='/hi method='post'>
            <input name = "name" palceholder="用户名"/><br>
            <input name = "pwd" palceholder="口令"/><br>
            <button>提交</button>
        </form>
        '''
    elif request.method == 'POST':
        name = request.form.get('name')
        pwd = request.form.get('pwd')

        if all((
            name.strip() == 'aaa',
            pwd.strip() == 'aaa'
        )):
            return '''
                <h2 style="color:blue">登陆成功</h2>
            '''
        else:
            return '''
                <h2 style="color:blue">登陆失败.<a href = "/hi">重试</a></h2></h2>
            '''
#启动flask服务
app.run(host='localhost',port=8000)
